package com.ts.api.module.product.service.impl;

import com.gitee.apanlh.util.base.BigDecimalUtils;
import com.gitee.apanlh.util.valid.ValidParam;
import com.ts.api.common.constant.api.ApiProviderEnum;
import com.ts.api.common.constant.product.ProductPlanTypeEnum;
import com.ts.api.module.product.entity.po.ProductPO;
import com.ts.api.module.product.entity.po.ProductPlanPO;
import com.ts.api.module.product.service.ProductPlanTypeService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class ProductPlanTypeServiceImpl implements ProductPlanTypeService {

    @Override
    public boolean hasLocalProduct(ProductPO productPO) {
        String apiDataExchange = productPO.getApiDataExchange();
        String apiApplyUrl = productPO.getApiApplyUrl();
        return ValidParam.isEmpty(apiDataExchange) && ValidParam.isEmpty(apiApplyUrl);
    }

    @Override
    public boolean hasOrgPlan(ProductPlanPO productPlanPO) {
        return ProductPlanTypeEnum.ORG.hasType(productPlanPO.getPlanType());
    }

    @Override
    public boolean hasLocalOrgPlan(ProductPO productPO, ProductPlanPO productPlanPO) {
        return this.hasOrgPlan(productPlanPO) && this.hasLocalProduct(productPO);
    }

    @Override
    public boolean hasApiOrgPlan(ProductPO productPO, ProductPlanPO productPlanPO) {
        return this.hasOrgPlan(productPlanPO) && !this.hasLocalProduct(productPO);
    }

    @Override
    public boolean hasSpecialPlan(ProductPlanPO productPlanPO) {
        //  本地特殊计划
        return ProductPlanTypeEnum.SPECIAL.hasType(productPlanPO.getPlanType());
    }

    @Override
    public boolean hasLocalSpecialPlan(ProductPO productPO, ProductPlanPO productPlanPO) {
        //  本地特殊计划
        return this.hasSpecialPlan(productPlanPO) && this.hasLocalProduct(productPO);
    }

    @Override
    public boolean hasApiSpecialPlan(ProductPO productPO, ProductPlanPO productPlanPO) {
        return this.hasSpecialPlan(productPlanPO) && !this.hasLocalProduct(productPO);
    }

    @Override
    public boolean hasPlatformPlan(ProductPlanPO productPlanPO) {
        //  平台计划
        return ProductPlanTypeEnum.PLATFORM.hasType(productPlanPO.getPlanType());
    }

    @Override
    public boolean hasPlatShare(ProductPlanPO productPlanPO) {
        if (!this.hasPlatformPlan(productPlanPO)) {
            return false;
        }
        BigDecimal share = productPlanPO.getShare();
        return BigDecimalUtils.compare(share, 0) > 0;
    }

    @Override
    public boolean hasPlatWeProvider(ProductPlanPO productPlanPO) {
        return this.hasPlatformPlan(productPlanPO) && ApiProviderEnum.WE.hasType(productPlanPO.getProviderType());
    }

    @Override
    public boolean hasPlatOtherProvider(ProductPlanPO productPlanPO) {
        return this.hasPlatformPlan(productPlanPO) && ApiProviderEnum.OTHER.hasType(productPlanPO.getProviderType());
    }
}
